package self.hoy.demo.grainmall.gateway.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.reactive.CorsWebFilter;
import org.springframework.web.cors.reactive.UrlBasedCorsConfigurationSource;

/**
 * @author hyh
 * @date 2020/7/15
 */
@Configuration
public class GrainMallCorsConfiguration {

    @Bean
    public CorsWebFilter corsWebFilter() {
        UrlBasedCorsConfigurationSource configSource = new UrlBasedCorsConfigurationSource();
        CorsConfiguration config = new CorsConfiguration();
        config.addAllowedOrigin("*");
        config.addAllowedMethod("*");
        config.addAllowedHeader("*");
//        config.addExposedHeaders();
        config.setAllowCredentials(true);
//        config.addMaxAge();

        configSource.registerCorsConfiguration("/**", config);
        return new CorsWebFilter(configSource);
    }
}
